package com.gitee.wsl.struct.either.ext

import arrow.core.Either
import arrow.core.Option
import arrow.core.None
import arrow.core.Some

/**
 * Turns your Either into an Option.
 */
fun <E, A> Either<E, A>?.asOption(): Option<A> =  if(this==null)
       None
    else when (this) {
       is Either.Left -> None
       is Either.Right -> Some(this.value)
}


/**
 * Turns the left side of your Either into an Option.
 */
fun <E, A> Either<E, A>.leftAsOption(): Option<E> = when (this) {
    is Either.Left -> Some(this.value)
    is Either.Right -> None
}

